package com.iwuke.dance.wallet.starlight_value;

import android.text.TextUtils;
import android.view.View;
import android.widget.ImageView;
import android.widget.TextView;

import com.iwuke.dance.R;
import com.iwuke.dance.activity.BaseActivity;
import com.iwuke.dance.gadget_view.TitleBarView;
import com.iwuke.dance.http_request.PathUrl;
import com.iwuke.dance.util.GlideUtil;
import com.iwuke.dance.util.ToastUtil;
import com.iwuke.dance.util.Util;
import com.iwuke.dance.util.merchants_connect.NetworkEvent;
import com.iwuke.dance.wallet.starlight_value.starlight_value_bean.StarlightTransactionRecordHomepageBean;

import java.util.HashMap;
import java.util.Map;

import de.greenrobot.event.Subscribe;
import de.greenrobot.event.ThreadMode;

/**
 * @author: 魏从响
 * @date: 2025/9/23
 * 余额明细
 */
public class BalanceDetailsActivity extends BaseActivity implements View.OnClickListener {


    private TitleBarView title_bar;
    private StarlightTransactionRecordHomepageBean data;
    private ImageView img_wechat;
    private TextView tv_starlight_value;
    private View v_line_1;
    private View v_credited;
    private View v_line_2;
    private View v_no_credited;
    private TextView tv_current_status_time;
    private TextView tv_request_progress;
    private TextView tv_credited;
    private TextView tv_withdrawal_amount;
    private TextView tv_application_time;
    private TextView tv_arrival_time;
    private TextView tv_withdrawal_platform;
    private TextView tv_withdrawal_account;
    private TextView tv_withdrawal_order_number;

    /**
     * @description 网络实时监听
     */
    @Subscribe(threadMode = ThreadMode.MainThread)
    public void onEvent(NetworkEvent networkEvent){
        BaseActivity.setConnect(BalanceDetailsActivity.this,networkEvent,title_bar);

    }

    @Override
    protected int getView() {
        return R.layout.activity_balance_details;
    }

    @Override
    protected void init(View mView) {

        title_bar = findViewById(R.id.title_bar);
        //微信图标
        img_wechat = findViewById(R.id.img_wechat);
        //星光值
        tv_starlight_value = findViewById(R.id.tv_starlight_value);
        //线
        v_line_1 = findViewById(R.id.v_line_1);
        //到账标志
        v_credited = findViewById(R.id.v_credited);
        //线
        v_line_2 = findViewById(R.id.v_line_2);
        //未到账标志
        v_no_credited = findViewById(R.id.v_no_credited);
        //当前状态和时间
        tv_current_status_time = findViewById(R.id.tv_current_status_time);
        //请求进度
        tv_request_progress = findViewById(R.id.tv_request_progress);
        //到账
        tv_credited = findViewById(R.id.tv_credited);
        //提现金额
        tv_withdrawal_amount = findViewById(R.id.tv_withdrawal_amount);
        //申请时间
        tv_application_time = findViewById(R.id.tv_application_time);
        //到账时间
        tv_arrival_time = findViewById(R.id.tv_arrival_time);
        //提现平台
        tv_withdrawal_platform = findViewById(R.id.tv_withdrawal_platform);
        //提现账号
        tv_withdrawal_account = findViewById(R.id.tv_withdrawal_account);
        //提现单号
        tv_withdrawal_order_number = findViewById(R.id.tv_withdrawal_order_number);


        title_bar.setTitleText("余额明细");
        title_bar.setLeftOnClick(this);

    }

    @Override
    protected void initData() {

        data = Util.getSerializableSafe(getIntent(), "data", StarlightTransactionRecordHomepageBean.class);

        requestBalance();

    }

    private void requestBalance() {
        Map<String, String> map = new HashMap<>();
        map.put("transactionRecordId", String.valueOf(data.id));

        PathUrl.getTransactionRecord(map, new PathUrl.DataCallBack<StarlightTransactionRecordHomepageBean>() {
            @Override
            public void onSucess(StarlightTransactionRecordHomepageBean bean) {

                if (bean!=null){

                    //微信图标
                    if (!TextUtils.isEmpty(bean.iconUrl)){
                        GlideUtil.setImageView(BalanceDetailsActivity.this,bean.iconUrl,img_wechat);
                    }else {
                        GlideUtil.setImageView(BalanceDetailsActivity.this,R.mipmap.img_wechat,img_wechat);
                    }

                    //星光值
                    tv_starlight_value.setText("-"+bean.amount);

                    switch (bean.status){
                        case 1:
                            //当前状态 "已获取"
                            //线
                            v_line_2.setVisibility(View.GONE);
                            //未到账标志
                            v_no_credited.setVisibility(View.GONE);
                            //线
                            v_line_1.setVisibility(View.VISIBLE);
                            //到账标志
                            v_credited.setVisibility(View.VISIBLE);

                            tv_request_progress.setTextColor(getColor(R.color.color_999));
                            tv_credited.setTextColor(getColor(R.color.color_333));
                            //到账
                            tv_credited.setText("到账\n"+data.updateTime);
                            break;

                        case 0:
                            //线
                            v_line_1.setVisibility(View.GONE);
                            //到账标志
                            v_credited.setVisibility(View.GONE);
                            //线
                            v_line_2.setVisibility(View.VISIBLE);
                            //未到账标志
                            v_no_credited.setVisibility(View.VISIBLE);
                            tv_request_progress.setTextColor(getColor(R.color.color_333));
                            tv_credited.setTextColor(getColor(R.color.color_999));
                            //到账
                            tv_credited.setText("到账");
                            break;
                        case 2:
                            //未获取
                            //线
                            v_line_1.setVisibility(View.GONE);
                            //到账标志
                            v_credited.setVisibility(View.GONE);
                            //线
                            v_line_2.setVisibility(View.VISIBLE);
                            //未到账标志
                            v_no_credited.setVisibility(View.VISIBLE);
                            tv_request_progress.setTextColor(getColor(R.color.color_999));
                            tv_credited.setTextColor(getColor(R.color.color_333));
                            //到账
                            tv_credited.setText("到账");
                            break;
                    }

                    //当前状态和时间
                    tv_current_status_time.setText("发起提现\n"+bean.createTime);
                    //请求进度
                    tv_request_progress.setText("请求微信中\n"+bean.createTime);

                    //提现金额
                    tv_withdrawal_amount.setText("¥"+ Util.setBigDecimal(bean.amount)+"元");
                    //申请时间
                    tv_application_time.setText(bean.createTime);
                    //到账时间
                    tv_arrival_time.setText(bean.updateTime);
                    //提现平台
                    tv_withdrawal_platform.setText("微信");
                    //提现账号
                    tv_withdrawal_account.setText(bean.withdrawAccount);
                    //提现单号
                    tv_withdrawal_order_number.setText(bean.orderId);

                }

            }

            @Override
            public void onFail(String errorCode) {
                ToastUtil.setToast(BalanceDetailsActivity.this,errorCode);
            }
        });
    }

    @Override
    public void onClick(View v) {
        if (v.getId()==R.id.img_left){
            finish();
        }

    }
}
